package abd.pr1.Interface;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;

import abd.pr1.Models.Serie;

public class BuscarSeriesPanel extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JList<Serie> listaSeries;
	private JButton info;
	private JButton buscarButton;
	private JTextField buscarTexto;
	public BuscarSeriesPanel(){
		super();
		this.build();
		
	}

	private void build() {
		
		this.setLayout(new BorderLayout());
		
		JPanel buscarContainer = new JPanel(new BorderLayout());
		JLabel buscarSeries = new JLabel("Buscar Serie");
		buscarTexto = new JTextField();
	    buscarButton= new JButton("Buscar");
		buscarButton.setActionCommand("buscar_serie");
		buscarContainer.add(buscarSeries,BorderLayout.WEST);
		buscarContainer.add(buscarTexto,BorderLayout.CENTER);
		buscarContainer.add(buscarButton,BorderLayout.EAST);
		
		this.add(buscarContainer,BorderLayout.NORTH);
				
		listaSeries = new JList<Serie>();
		
		this.add(listaSeries, BorderLayout.CENTER);
		

	    info= new JButton("Mas informacion");
	    info.setActionCommand("info_serie");
		this.add(info, BorderLayout.SOUTH);

	}
	public String getBuscarTexto(){
		return this.buscarTexto.getText();
	}
	public void addListener(ActionListener a){
		info.addActionListener(a);
		buscarButton.addActionListener(a);
	}
	public void setListaseries(List<Serie> series){
		listaSeries.setListData(series.toArray(new Serie[series.size()]));
	}
	
	public Serie getSelectedSerie(){
		return listaSeries.getSelectedValue();
	}

}
